<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>设置 - 析码无界</title>
    <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.4/css/bootstrap.min.css">
    <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">
    <link rel="stylesheet" href="http://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css">
    <script src="http://cdn.bootcss.com/jquery/1.11.2/jquery.min.js"></script>
    <script src="http://cdn.bootcss.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
    <style>
        body {
            font-family: 'Microsoft YaHei', sans-serif;
            background-color: #f5f5f5;
        }
        .navbar {
            border-radius: 0;
            background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
            border: none;
        }
        .navbar-brand {
            color: white !important;
            font-weight: bold;
        }
        .navbar-nav > li > a {
            color: rgba(255,255,255,0.9) !important;
        }
        .navbar-nav > li > a:hover {
            color: white !important;
            background-color: rgba(255,255,255,0.1) !important;
        }
        .main-content {
            margin-top: 20px;
            min-height: calc(100vh - 100px);
        }
        .panel {
            border: none;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
            border-radius: 8px;
        }
        .panel-heading {
            background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
            color: white;
            border-radius: 8px 8px 0 0;
            padding: 15px 20px;
        }
        .panel-title {
            font-size: 18px;
            font-weight: 600;
        }
        .settings-menu {
            list-style: none;
            padding: 0;
        }
        .settings-menu li {
            border-bottom: 1px solid #eee;
        }
        .settings-menu li:last-child {
            border-bottom: none;
        }
        .settings-menu a {
            display: block;
            padding: 15px 20px;
            color: #333;
            text-decoration: none;
            transition: background-color 0.3s;
        }
        .settings-menu a:hover {
            background-color: #f8f9fa;
            color: #667eea;
        }
        .settings-menu a i {
            margin-right: 10px;
            width: 20px;
        }
        .avatar-container {
            display: inline-block;
            margin-right: 10px;
            vertical-align: middle;
        }
        .teacher-avatar {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            border: 2px solid rgba(255,255,255,0.8);
            object-fit: cover;
            cursor: pointer;
            transition: transform 0.2s;
        }
        .teacher-avatar:hover {
            transform: scale(1.1);
        }
    </style>
    <script>
        function previewAvatar(input) {
            if (input.files && input.files[0]) {
                var reader = new FileReader();
                reader.onload = function(e) {
                    document.getElementById('avatarPreview').src = e.target.result;
                };
                reader.readAsDataURL(input.files[0]);
                // 自动提交表单
                document.getElementById('avatarForm').submit();
            }
        }
    </script>
</head>
<body>
    <!-- 导航栏 -->
    <nav class="navbar navbar-default">
        <div class="container-fluid">
            <div class="navbar-header">
                <a class="navbar-brand" href="#" style="display: flex; align-items: center;">
                    <div class="avatar-container">
                        <img th:src="${session.teacher?.avatar != null and !session.teacher.avatar.isEmpty() ? '/' + session.teacher.avatar : ''}" 
                             class="teacher-avatar"
                             th:onclick="'location.href=\'' + @{/teacher/settings} + '\''"
                             onerror="if(this.src.indexOf('data:image') === -1) { this.onerror=null; this.src=''; }"
                             alt="头像">
                    </div>
                    <span><i class="fa fa-graduation-cap"></i> 析码无界 - 教师管理平台</span>
                </a>
            </div>
            <ul class="nav navbar-nav">
                <li><a th:href="@{/teacher/profile}">个人信息</a></li>
                <li class="active"><a th:href="@{/teacher/settings}"><i class="fa fa-cog"></i> 设置</a></li>
                <li><a th:href="@{/assignment/list}">作业管理</a></li>
                <li><a th:href="@{/class/list}">班级管理</a></li>
                <li><a th:href="@{/teacher/student/list}"><i class="fa fa-list"></i> 学生列表</a></li>
                <li><a th:href="@{/teacher/student/add}"><i class="fa fa-plus"></i> 添加学生</a></li>
            </ul>
            <ul class="nav navbar-nav navbar-right">
                <li><a href="/"><i class="fa fa-sign-out"></i> 退出登录</a></li>
            </ul>
        </div>
    </nav>

    <div class="container main-content">
        <div class="row">
            <div class="col-md-8 col-md-offset-2">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title"><i class="fa fa-cog"></i> 设置</h3>
                    </div>
                    <div class="panel-body">
                        <div th:if="${message}" class="alert alert-success" th:text="${message}"></div>
                        <div th:if="${error}" class="alert alert-danger" th:text="${error}"></div>
                        
                        <!-- 头像设置 -->
                        <div style="margin-bottom: 30px; padding: 20px; background-color: #f8f9fa; border-radius: 8px;">
                            <h4 style="margin-bottom: 20px;"><i class="fa fa-user-circle"></i> 头像设置</h4>
                            <div class="text-center">
                                <div style="position: relative; display: inline-block;">
                                    <img id="avatarPreview" 
                                         th:src="${session.teacher?.avatar != null and !session.teacher.avatar.isEmpty() ? '/' + session.teacher.avatar : ''}" 
                                         style="width: 120px; height: 120px; border-radius: 50%; border: 3px solid #667eea; cursor: pointer; object-fit: cover;"
                                         onclick="document.getElementById('avatarInput').click()"
                                         onerror="if(this.src.indexOf('data:image') === -1) { this.onerror=null; this.src=''; }">
                                    <div style="position: absolute; bottom: 0; right: 0; background-color: #667eea; color: white; width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; border: 3px solid white;"
                                         onclick="document.getElementById('avatarInput').click()">
                                        <i class="fa fa-camera"></i>
                                    </div>
                                </div>
                                <p style="margin-top: 15px; color: #666;">
                                    <small>点击头像或相机图标更换头像</small>
                                </p>
                                <form th:action="@{/teacher/avatar/upload}" method="post" enctype="multipart/form-data" id="avatarForm" style="display: none;">
                                    <input type="file" name="avatar" id="avatarInput" accept="image/*" onchange="previewAvatar(this)">
                                </form>
                                <div style="margin-top: 20px;">
                                    <a th:href="@{/teacher}" class="btn btn-primary">
                                        <i class="fa fa-home"></i> 返回主页
                                    </a>
                                </div>
                            </div>
                        </div>
                        
                        <ul class="settings-menu">
                            <li>
                                <a th:href="@{/teacher/changePassword}">
                                    <i class="fa fa-lock"></i>
                                    <strong>更改密码</strong>
                                    <span class="pull-right text-muted">
                                        <i class="fa fa-chevron-right"></i>
                                    </span>
                                </a>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>

